//
//  BaseNavigationViewController.m
//  yiYuanDuoBao
//
//  Created by 罗李苏 on 16/11/21.
//  Copyright © 2016年 罗李苏. All rights reserved.
//

#import "BaseNavigationViewController.h"
#import "UIColor+CBJExtention.h"
#import "UIImage+EXtension.h"
//黄色导航栏
#define NavBarColor [UIColor colorWithRed:250/255.0 green:227/255.0 blue:111/255.0 alpha:1.0]
@interface BaseNavigationViewController ()
@property (nonatomic, assign,getter=isHiddenBottom) BOOL hiddenBottom;
@end

@implementation BaseNavigationViewController
+ (void)initialize{

    //获取外观对象
    UINavigationBar *navBar = [UINavigationBar appearance];
    //设置返回按钮
    navBar.backIndicatorImage = [UIImage imageNamed:@"导航栏_返回_icon"];
    // 设置背景图片
//    [navBar setBackgroundImage:[UIImage imageNamed:@"button"] forBarMetrics:UIBarMetricsDefault];
    
    // 设置标题栏文字颜色
//    [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//    navBar.backIndicatorImage = [UIImage imageNamed:@"back"];
    // 设置两侧按钮颜色
//    [navBar setTintColor:[UIColor whiteColor]];
    
}
+ (void)load{
#warning 尼玛在这里设置没作用
    //设置tabBarItem的文字属性
//    UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[self]];
//    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
//    dict[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//    dict[NSForegroundColorAttributeName] = [UIColor colorWithString:@"666666"];
//
//    [item setTitleTextAttributes:dict forState:UIControlStateNormal];
//    
//    NSMutableDictionary *selectedDict = [NSMutableDictionary dictionary];
//    selectedDict[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//    selectedDict[NSForegroundColorAttributeName] = [UIColor colorWithString:@"FF2104"];
//    [item setTitleTextAttributes:selectedDict forState:UIControlStateSelected];
    
    
    //设置navigationBar的属性
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[self]];
    [navBar setBackgroundImage:[UIImage imageWithColor:NavBarColor] forBarMetrics:UIBarMetricsDefault];
    NSMutableDictionary *navDic = [NSMutableDictionary dictionary];
    navDic[NSFontAttributeName] = [UIFont systemFontOfSize:25];
    [navBar setTitleTextAttributes:navDic];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
#warning 跳转了第二层控制器后隐藏地步的tabBar
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

//    if (self.viewControllers.count > 0) {
//        
//        viewController.hidesBottomBarWhenPushed = YES;
//    }
    
    if (self.isHiddenBottom) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        
        // 创建leftBtn覆盖backbarbutton。
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"导航栏_返回_icon"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    }else{
    
        self.hiddenBottom = YES;
    }
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"导航栏_返回_icon"]]];
    //    self.navigationItem.leftBarButtonItem = item;
    self.topViewController.navigationItem.backBarButtonItem = item;

    [super pushViewController:viewController animated:YES];
}
- (void)back{

    [self popViewControllerAnimated:YES];
}
@end
